﻿#include "cameradaheng.h"
#include "logger.h"
static void GX_STDC OnFrameCallbackFun(GX_FRAME_CALLBACK_PARAM* pFrame){
    if (pFrame ->status == 0){
        //printf("Get frame blockId = %llu\n", pFrame->frameInfo.blockId);
        auto pUser = pFrame->pUserParam;
        auto pCamera = static_cast<Camera*>(pUser);

        if(pCamera==nullptr)
            return;

        ImageInfo imgInfo;
        imgInfo.nWidth = pFrame->nWidth;
        imgInfo.nHeight = pFrame->nHeight;
        imgInfo.pData = (unsigned char*)pFrame->pImgBuf;
        imgInfo.nDataLen = pFrame->nImgSize;
        imgInfo.enPixelType = pFrame->nPixelFormat;
        pCamera->preProcessImage(imgInfo);
    } else {
        printf("pFrame is NULL\n");
        return;
    }
}

//掉线回调处理函数
static void GX_STDC OnDeviceOfflineCallbackFun(void* pUserParam)
{
    printf("MV_EXCEPTION_DEV_DISCONNECT");
    auto pCamera = static_cast<Camera*>(pUserParam);
    if(pCamera==nullptr)
        return;

     pCamera->emitMessage(tr(u8"<font color=\'red\'>相机离线</font>"), CameraMsgLevel::Warning);
    return;
}

CameraDaheng::CameraDaheng(const std::string name):Camera(name)
{

}

void CameraDaheng::initialize()
{
    GX_STATUS status = GX_STATUS_SUCCESS;

    GX_OPEN_PARAM stOpenParam;
    uint32_t nDeviceNum = 0;
    //初始化库
    status = GXInitLib();
    if (status!= GX_STATUS_SUCCESS){
        return;
    }

    //枚举设备列表
    status = GXUpdateDeviceList(&nDeviceNum, 1000);
    if ((status!= GX_STATUS_SUCCESS)||(nDeviceNum<= 0)){
        return;
    }

    int nIndex = -1;
    if(nDeviceNum > 0){
        GX_DEVICE_BASE_INFO *pBaseinfo = new GX_DEVICE_BASE_INFO[nDeviceNum];
        size_t nSize = nDeviceNum * sizeof(GX_DEVICE_BASE_INFO);
        //获取所有设备的基础信息
        status = GXGetAllDeviceBaseInfo(pBaseinfo, &nSize);
        if (status != GX_STATUS_SUCCESS){
            printf("GXGetAllDeviceBaseInfo failed! ErrorCode[%d]\n", status);
            delete []pBaseinfo;
            return;
        }

        for (unsigned int i = 0; i < nDeviceNum; i++){
            printf("[device %d]:\n", i);

            auto pDeviceInfo = pBaseinfo[i];
            std::string cameraName = std::string(reinterpret_cast<char*>(pDeviceInfo.szUserID));
            if(cameraName == m_name){
                nIndex=i;
                break;
            }
        }
        delete []pBaseinfo;
    }

    if (nIndex == -1){
        printf("%s unavailable:\n", m_name.c_str());
        return ;
    }

    //打开设备
    stOpenParam.accessMode = GX_ACCESS_EXCLUSIVE;
    stOpenParam.openMode = GX_OPEN_USERID;
    stOpenParam.pszContent = const_cast<char*>(m_name.c_str());
    status = GXOpenDevice(&stOpenParam, &m_handle);
    if (status == GX_STATUS_SUCCESS){
        //设置相机的流通道包长属性，提高网络相机的采集性能
        bool bImplementPacketSize = false;
        uint32_t unPacketSize = 0;
        // 判断设备是否支持流通道数据包功能
        status = GXIsImplemented(m_handle, GX_INT_GEV_PACKETSIZE, &bImplementPacketSize);
        if (bImplementPacketSize){
            // 获取当前网络环境的最优包长
            status = GXGetOptimalPacketSize (m_handle, &unPacketSize);
            // 将最优包长设置为当前设备的流通道包长值
            status = GXSetInt (m_handle, GX_INT_GEV_PACKETSIZE, unPacketSize);
        }

        //注册图像处理回调函数
        status = GXRegisterCaptureCallback(m_handle, this, OnFrameCallbackFun);
    }

    m_status= Closed;
}

void CameraDaheng::openCamera()
{
    GX_STATUS status = GX_STATUS_SUCCESS;

   //设置触发模式为 OFF
   status = GXSetEnum(m_handle, GX_ENUM_TRIGGER_MODE, GX_TRIGGER_MODE_OFF);
   if (status != GX_STATUS_SUCCESS){
       printf("Set GX_TRIGGER_MODE_OFF failed! ErrorCode[%d]\n", status);
       return;
   }

   status = GXGetInt(m_handle, GX_INT_PAYLOAD_SIZE, &m_payLoadSize);
   if (status != GX_STATUS_SUCCESS){
       printf("Get GX_INT_PAYLOAD_SIZE failed! ErrorCode[%d]\n", status);
       return;
   }
   status = GXGetInt(m_handle, GX_INT_WIDTH, &m_imgWidth);
   if (status != GX_STATUS_SUCCESS){
       printf("Get GX_INT_PAYLOAD_SIZE failed! ErrorCode[%d]\n", status);
       return;
   }
   status = GXGetInt(m_handle, GX_INT_HEIGHT, &m_imgHeight);
   if (status != GX_STATUS_SUCCESS){
       printf("Get GX_INT_PAYLOAD_SIZE failed! ErrorCode[%d]\n", status);
       return;
   }

   bool m_bColorFilter;
   status = GXIsImplemented(m_handle, GX_ENUM_PIXEL_COLOR_FILTER, &m_bColorFilter);
   if (m_bColorFilter){
       status = GXGetEnum(m_handle, GX_ENUM_PIXEL_COLOR_FILTER, &m_nPixelColorFilter);
       if (status != GX_STATUS_SUCCESS){
           printf("Get GX_ENUM_PIXEL_COLOR_FILTER failed! ErrorCode[%d]\n", status);
           return;
       }
   }

   m_pBufferRGB = new BYTE[(size_t)(m_imgWidth * m_imgWidth * 3)];
   if (m_pBufferRGB == NULL){
       printf("Malloc buffer for RGB failed\n");
       return;
   }

   //注册掉线回调函数
   status = GXRegisterDeviceOfflineCallback(m_handle, this, OnDeviceOfflineCallbackFun, &hCB);
   if (status != GX_STATUS_SUCCESS){
       printf("GXRegisterCaptureCallbackg failed! ErrorCode[%d]\n", status);
       return;
   }

    //发送开采命令
    status = GXSendCommand(m_handle, GX_COMMAND_ACQUISITION_START);
    if (status != GX_STATUS_SUCCESS){
        printf("Start grabbing failed! ErrorCode[%d]\n", status);
        return;
    }

    printf("%s open successed!\n", m_name.c_str());
    m_status = Opened;
    m_reconnect_cnt = 0;
    emit cameraWarning("");

}

void CameraDaheng::triggerSoftware()
{
    GX_STATUS status = GX_STATUS_SUCCESS;
    status = GXFlushQueue(m_handle);
    if (status != GX_STATUS_SUCCESS){
        printf("GXFlushQueue failed! ErrorCode[%d]\n", status);
        return;
    }
    status = GXSendCommand(m_handle, GX_COMMAND_TRIGGER_SOFTWARE);
    if (status != GX_STATUS_SUCCESS){
        printf("Trigger Software failed! ErrorCode[%d]\n", status);
        return;
    }
}

void CameraDaheng::setTriggerModeOff()
{
    //设置触发模式为 OFF
    GX_STATUS status = GXSetEnum(m_handle, GX_ENUM_TRIGGER_MODE, GX_TRIGGER_MODE_OFF);
    if (status != GX_STATUS_SUCCESS){
        printf("Set GX_TRIGGER_MODE_OFF failed! ErrorCode[%d]\n", status);
        return;
    }
}
void CameraDaheng::setTriggerModeSoftware()
{
    GX_STATUS status = GX_STATUS_SUCCESS;

    //设置采集模式, 一般相机的默认采集模式为连续模式
    int64_t nAcqMode = GX_ACQ_MODE_CONTINUOUS;
    status = GXSetEnum(m_handle, GX_ENUM_ACQUISITION_MODE, nAcqMode);
    if (status != GX_STATUS_SUCCESS){
        printf("Set GX_ACQ_MODE_CONTINUOUS failed! ErrorCode[%d]\n", status);
        return;
    }
    //设置触发模式为 ON
    status = GXSetEnum(m_handle, GX_ENUM_TRIGGER_MODE, GX_TRIGGER_MODE_ON);
    if (status != GX_STATUS_SUCCESS){
        printf("Set GX_TRIGGER_MODE_ON failed! ErrorCode[%d]\n", status);
        return;
    }
    //设置触发激活方式为上升沿
    status = GXSetEnum(m_handle, GX_ENUM_TRIGGER_ACTIVATION,
                       GX_TRIGGER_ACTIVATION_RISINGEDGE);
    if (status != GX_STATUS_SUCCESS){
        printf("Set GX_TRIGGER_ACTIVATION_RISINGEDGE failed! ErrorCode[%d]\n", status);
        return;
    }
}

void CameraDaheng::closeCamera()
{
    if (m_status == Opened) {
        m_status = Closing;
        //发送停采命令
        GX_STATUS status = GXSendCommand(m_handle, GX_COMMAND_ACQUISITION_STOP);

        //注销采集回调
        status = GXUnregisterCaptureCallback(m_handle);

        //注销设备掉线事件回调
        status= GXUnregisterDeviceOfflineCallback(m_handle, hCB);

        //关闭设备
        status = GXCloseDevice(m_handle);
        if (GX_STATUS_SUCCESS != status){
            printf("Close camera failed! ErrorCode[%d]\n", status);
            return;
        }
        m_status = Closed;
        //在结束的时候调用 GXCLoseLib()释放资源
        status = GXCloseLib();
        if (GX_STATUS_SUCCESS != status){
            printf("Close lib failed! ErrorCode[%d]\n", status);
            return;
        }

        if(m_pBufferRGB) {
            delete[] m_pBufferRGB;
        }
    }
}

void CameraDaheng::quit()
{
    closeCamera();
    deleteLater();
}

void CameraDaheng::readCameraParams()
{
    if(m_status!=Opened)
        return;
    /*
    /////////////////////////////exposure time//////////////////////////
    double expCurValue;
    auto nRet = IMV_GetDoubleFeatureValue(m_handle, "ExposureTime",&expCurValue);
    if (IMV_OK != nRet){
        printf("%s GetExposureTime value fail! ErrorCode:[%d]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_GetExposureTime fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
        return;
    }
    double expMax;
    nRet = IMV_GetDoubleFeatureMax(m_handle, "ExposureTime",&expMax);
    if (IMV_OK != nRet){
        printf("%s GetExposureTime max fail! ErrorCode:[0x%x]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_GetExposureTime fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
        return;
    }
    double expMin;
    nRet = IMV_GetDoubleFeatureMin(m_handle, "ExposureTime",&expMin);
    if (IMV_OK != nRet){
        printf("%s GetExposureTime min fail! ErrorCode:[0x%x]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_GetExposureTime fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
        return;
    }

    ///////////////////////////////////white balance red////////////////////
    IMV_SetEnumFeatureSymbol(m_handle,"BalanceRatioSelector","Red");
    double wb_redCurValue;
    nRet = IMV_GetDoubleFeatureValue(m_handle, "BalanceRatio",&wb_redCurValue);
    if (IMV_OK != nRet){
        printf("%s Red fail! ErrorCode:[%d]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_GetExposureTime fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
        return;
    }
    double wb_redMax;
    nRet = IMV_GetDoubleFeatureMax(m_handle, "BalanceRatio",&wb_redMax);
    if (IMV_OK != nRet){
        printf("%s Red fail! ErrorCode:[0x%x]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_GetExposureTime fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
        return;
    }
    double wb_redMin;
    nRet = IMV_GetDoubleFeatureMin(m_handle, "BalanceRatio",&wb_redMin);
    if (IMV_OK != nRet){
        printf("%s Red fail! ErrorCode:[0x%x]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_GetExposureTime fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
        return;
    }
    ///////////////////////////////////white balance green////////////////////
    IMV_SetEnumFeatureSymbol(m_handle,"BalanceRatioSelector","Green");
    double wb_greenCurValue;
    nRet = IMV_GetDoubleFeatureValue(m_handle, "BalanceRatio",&wb_greenCurValue);
    if (IMV_OK != nRet){
        printf("%s Green fail! ErrorCode:[0x%x]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_GetExposureTime fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
        return;
    }
    double wb_greenMax;
    nRet = IMV_GetDoubleFeatureMax(m_handle, "BalanceRatio",&wb_greenMax);
    if (IMV_OK != nRet){
        printf("%s Green fail! ErrorCode:[0x%x]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_GetExposureTime fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
        return;
    }
    double wb_greenMin;
    nRet = IMV_GetDoubleFeatureMin(m_handle, "BalanceRatio",&wb_greenMin);
    if (IMV_OK != nRet){
        printf("%s Green fail! ErrorCode:[0x%x]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_GetExposureTime fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
        return;
    }
    ///////////////////////////////////white balance blue////////////////////
    IMV_SetEnumFeatureSymbol(m_handle,"BalanceRatioSelector","Blue");
    double wb_blueCurValue;
    nRet = IMV_GetDoubleFeatureValue(m_handle, "BalanceRatio",&wb_blueCurValue);
    if (IMV_OK != nRet){
        printf("%s Blue fail! ErrorCode:[0x%x]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_GetExposureTime fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
        return;
    }
    double wb_blueMax;
    nRet = IMV_GetDoubleFeatureMax(m_handle, "BalanceRatio",&wb_blueMax);
    if (IMV_OK != nRet){
        printf("%s Blue fail! ErrorCode:[0x%x]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_GetExposureTime fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
        return;
    }
    double wb_blueMin;
    nRet = IMV_GetDoubleFeatureMin(m_handle, "BalanceRatio",&wb_blueMin);
    if (IMV_OK != nRet){
        printf("%s Blue fail! ErrorCode:[0x%x]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_GetExposureTime fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
        return;
    }
    ////////////////////////////offset x//////////////////
    IMV_SetEnumFeatureSymbol(m_handle,"RegionSelector","Region0");
    int64_t off_xCurValue;
    nRet = IMV_GetIntFeatureValue(m_handle, "OffsetX",&off_xCurValue);
    if (IMV_OK != nRet){
        printf("%s Red fail! ErrorCode:[0x%x]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_GetExposureTime fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
        return;
    }
    int64_t off_xMax;
    nRet = IMV_GetIntFeatureMax(m_handle, "OffsetX",&off_xMax);
    if (IMV_OK != nRet){
        printf("%s Red fail! ErrorCode:[0x%x]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_GetExposureTime fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
        return;
    }
    int64_t off_xMin;
    nRet = IMV_GetIntFeatureMin(m_handle, "OffsetX",&off_xMin);
    if (IMV_OK != nRet){
        printf("%s Red fail! ErrorCode:[0x%x]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_GetExposureTime fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
        return;
    }
    int64_t off_xInc;
    nRet = IMV_GetIntFeatureInc(m_handle, "OffsetX",&off_xInc);
    if (IMV_OK != nRet){
        printf("%s Red fail! ErrorCode:[0x%x]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_GetExposureTime fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
        return;
    }
    ////////////////////////////offset y//////////////////
    IMV_SetEnumFeatureSymbol(m_handle,"RegionSelector","Region0");
    int64_t off_yCurValue;
    nRet = IMV_GetIntFeatureValue(m_handle, "OffsetY",&off_yCurValue);
    if (IMV_OK != nRet){
        printf("%s Red fail! ErrorCode:[0x%x]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_GetExposureTime fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
        return;
    }
    int64_t off_yMax;
    nRet = IMV_GetIntFeatureMax(m_handle, "OffsetY",&off_yMax);
    if (IMV_OK != nRet){
        printf("%s Red fail! ErrorCode:[0x%x]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_GetExposureTime fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
        return;
    }
    int64_t off_yMin;
    nRet = IMV_GetIntFeatureMin(m_handle, "OffsetY",&off_yMin);
    if (IMV_OK != nRet){
        printf("%s Red fail! ErrorCode:[0x%x]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_GetExposureTime fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
        return;
    }
    int64_t off_yInc;
    nRet = IMV_GetIntFeatureInc(m_handle, "OffsetY",&off_yInc);
    if (IMV_OK != nRet){
        printf("%s Red fail! ErrorCode:[0x%x]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_GetExposureTime fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
        return;
    }

    CameraParams cp;
    cp.exp.fCurValue = expCurValue;
    cp.exp.fMax = expMax;
    cp.exp.fMin = expMin;
    cp.wb_r.nCurValue = wb_redCurValue;
    cp.wb_r.nMax = wb_redMax;
    cp.wb_r.nMin = wb_redMin;
    cp.wb_r.nInc = 1;
    cp.wb_g.nCurValue = wb_greenCurValue;
    cp.wb_g.nMax = wb_greenMax;
    cp.wb_g.nMin = wb_greenMin;
    cp.wb_g.nInc = 1;
    cp.wb_b.nCurValue = wb_blueCurValue;
    cp.wb_b.nMax = wb_blueMax;
    cp.wb_b.nMin = wb_blueMin;
    cp.wb_b.nInc = 1;
    cp.off_x.nCurValue = off_xCurValue;
    cp.off_x.nMax = off_xMax;
    cp.off_x.nMin = off_xMin;
    cp.off_x.nInc = off_xInc;
    cp.off_y.nCurValue = off_yCurValue;
    cp.off_y.nMax = off_yMax;
    cp.off_y.nMin = off_yMin;
    cp.off_y.nInc = off_yInc;

    emit sendCameraParams(m_name,cp);
    */
}

void CameraDaheng::writeCameraParams(const std::string& camName, const CameraParams &cp)
{
    /*
    if(m_status!=Opened ||camName!=m_name)
        return;

    int nRet = IMV_OK;
    nRet =IMV_SetDoubleFeatureValue(m_handle,"ExposureTime",cp.exp.fCurValue);
    if (IMV_OK != nRet){
        printf("%s SetExposureTime fail! ErrorCode:[0x%x]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_SetExposureTime fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
    }

    nRet = IMV_SetEnumFeatureSymbol(m_handle,"BalanceRatioSelector","Red");
    nRet = IMV_SetDoubleFeatureValue(m_handle,"BalanceRatio",cp.wb_r.nCurValue);
    if (IMV_OK != nRet){
        printf("%s MV_CC_SetBalanceRatioRed fail! ErrorCode:[0x%x]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" SetBalanceRatioRed fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
    }
    nRet = IMV_SetEnumFeatureSymbol(m_handle,"BalanceRatioSelector","Green");
    nRet = IMV_SetDoubleFeatureValue(m_handle,"BalanceRatio",cp.wb_g.nCurValue);
    if (IMV_OK != nRet){
        printf("%s MV_CC_SetBalanceRatioGreen fail! ErrorCode:[0x%x]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" SetBalanceRatioGreen fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
    }
    nRet = IMV_SetEnumFeatureSymbol(m_handle,"BalanceRatioSelector","Blue");
    nRet =IMV_SetDoubleFeatureValue(m_handle,"BalanceRatio",cp.wb_b.nCurValue);
    if (IMV_OK != nRet){
        printf("%s MV_CC_SetBalanceRatioBlue fail! ErrorCode:[0x%x]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" SetBalanceRatioBlue fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
    }

    nRet = IMV_SetIntFeatureValue(m_handle,"OffsetX",cp.off_x.nCurValue);
    if (IMV_OK != nRet){
        printf("%s SetAOIoffsetX fail! ErrorCode:[%d]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_SetAOIoffsetX fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
    }
    nRet = IMV_SetIntFeatureValue(m_handle,"OffsetY",cp.off_y.nCurValue);
    if (IMV_OK != nRet){
        printf("%s SetAOIoffsetY fail! ErrorCode:[%d]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_SetAOIoffsetY fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
    }

    //save params to user set
    nRet = IMV_SetEnumFeatureSymbol(m_handle, "UserSetSelector", "UserSet1");
    if (IMV_OK != nRet){
        printf("%s SetUserSetSelector fail! ErrorCode:[%d]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_SetUserSetSelector fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
    }

    nRet =IMV_ExecuteCommandFeature(m_handle,"UserSetSave");
    if (IMV_OK != nRet){
        printf("%s SetUserSerSave fail! ErrorCode:[%d]\n",m_name.c_str(), nRet);
        //LOG(WARNING)<<m_camName<<" MV_CC_SetUserSerSave fail! ErrorCode: "<< QByteArray::number(nRet,16).toStdString();
    }
    */
}

void CameraDaheng::preProcessImage(const ImageInfo &imgInfo)
{
    if(imgInfo.pData==nullptr || m_status != Opened)
        return;

    // convert Raw8 to BGR
    bool isFlip = false;
    DX_RGB_CHANNEL_ORDER emChannelOrder = DX_ORDER_BGR;
    DxRaw8toRGB24Ex(imgInfo.pData, m_pBufferRGB
                    ,(VxUint32)(m_imgWidth)
                    ,(VxUint32)(m_imgHeight)
                    ,RAW2RGB_NEIGHBOUR
                    ,DX_PIXEL_COLOR_FILTER(m_nPixelColorFilter)
                    ,isFlip
                    ,emChannelOrder);

    cv::Mat cv_img;
    cv_img.create(m_imgHeight, m_imgWidth, CV_8UC3);

    memcpy(cv_img.data, m_pBufferRGB, m_imgWidth * m_imgHeight * 3);
    emit sendCVImage(m_name, cv_img);
}


bool CameraDaheng::isColor(int pixelFormat)
{
    switch(pixelFormat){
    case GX_PIXEL_FORMAT_BAYER_GR8:
    case GX_PIXEL_FORMAT_BAYER_RG8:
    case GX_PIXEL_FORMAT_BAYER_GB8:
    case GX_PIXEL_FORMAT_BAYER_BG8:
    case GX_PIXEL_FORMAT_BAYER_GR10:
    case GX_PIXEL_FORMAT_BAYER_RG10:
    case GX_PIXEL_FORMAT_BAYER_GB10:
    case GX_PIXEL_FORMAT_BAYER_BG10:
    case GX_PIXEL_FORMAT_BAYER_GR12:
    case GX_PIXEL_FORMAT_BAYER_RG12:
    case GX_PIXEL_FORMAT_BAYER_GB12:
    case GX_PIXEL_FORMAT_BAYER_BG12:
    case GX_PIXEL_FORMAT_BAYER_GR16:
    case GX_PIXEL_FORMAT_BAYER_RG16:
    case GX_PIXEL_FORMAT_BAYER_GB16:
    case GX_PIXEL_FORMAT_BAYER_BG16:
    case GX_PIXEL_FORMAT_RGB8_PLANAR:
    case GX_PIXEL_FORMAT_RGB10_PLANAR:
    case GX_PIXEL_FORMAT_RGB12_PLANAR:
    case GX_PIXEL_FORMAT_RGB16_PLANAR:
    case GX_PIXEL_FORMAT_RGB8 :
    case GX_PIXEL_FORMAT_RGB10:
    case GX_PIXEL_FORMAT_RGB12:
    case GX_PIXEL_FORMAT_RGB14:
    case GX_PIXEL_FORMAT_RGB16:
    case GX_PIXEL_FORMAT_BGR8 :
    case GX_PIXEL_FORMAT_BGR10:
    case GX_PIXEL_FORMAT_BGR12:
    case GX_PIXEL_FORMAT_BGR14:
    case GX_PIXEL_FORMAT_BGR16:
    case GX_PIXEL_FORMAT_RGBA8:
    case GX_PIXEL_FORMAT_BGRA8:
    case GX_PIXEL_FORMAT_ARGB8:
    case GX_PIXEL_FORMAT_ABGR8:
    case GX_PIXEL_FORMAT_YUV444_8:
    case GX_PIXEL_FORMAT_YUV422_8:
    case GX_PIXEL_FORMAT_YUV411_8:
    case GX_PIXEL_FORMAT_YUV420_8_PLANAR:
    case GX_PIXEL_FORMAT_YCBCR444_8:
    case GX_PIXEL_FORMAT_YCBCR422_8:
    case GX_PIXEL_FORMAT_YCBCR411_8:
    case GX_PIXEL_FORMAT_YCBCR601_444_8:
    case GX_PIXEL_FORMAT_YCBCR601_422_8:
    case GX_PIXEL_FORMAT_YCBCR601_411_8:
    case GX_PIXEL_FORMAT_YCBCR709_444_8:
    case GX_PIXEL_FORMAT_YCBCR709_422_8:
    case GX_PIXEL_FORMAT_YCBCR709_411_8:

       return true;
    default:
       return false;
    }
}

bool CameraDaheng::isMono(int pixelFormat)
{
    switch(pixelFormat){
    case GX_PIXEL_FORMAT_MONO8        :
    case GX_PIXEL_FORMAT_MONO8_SIGNED :
    case GX_PIXEL_FORMAT_MONO10       :
    case GX_PIXEL_FORMAT_MONO12       :
    case GX_PIXEL_FORMAT_MONO14       :
    case GX_PIXEL_FORMAT_MONO16       :
        return true;
    default:
        return false;
    }
}


void CameraDaheng::setExposureTime(const std::string &camName, const FloatValue &value)
{

}
